/**
 * JAVACC DEMO 1.0
 */
package com.apache.client;

import com.apache.method.SystemRunnable;
import org.apache.log4j.Logger;

import java.util.Map;

/**
 * description:  日志添加线程
 *
 * @author Hou Dayu 创建时间：2016-8-8
 */
public class LoggerClientRunnable extends SystemRunnable {

    private Logger log = Logger.getLogger(LoggerClientRunnable.class);

    private Object obj;

    private Map<String, Object> logMap;

    public LoggerClientRunnable(Object obj, Map<String, Object> logMap) {
        this.obj = obj;
        this.logMap = logMap;
    }

    /**
     * TODO 简单描述该方法的实现功能（可选）.
     *
     * @see java.lang.Runnable#run()
     */
    public void run() {
        try {
            String mark = "false";
            String returnValue = String.valueOf(logMap.get("log_returnValue"));
            if ("save".equals(logMap.get("logType"))) {
                if (!isNull(returnValue)) {
                    mark = "true";
                }
            } else if ("edit".equals(logMap.get("logType")) || "delete"
                    .equals(logMap.get("logType"))) {
                if (!isNull(returnValue)) {
                    mark = returnValue;
                }
            } else {
                mark = returnValue;
            }
            if (!"true".equals(mark))
                return;
            if (null != obj) {
                Map beanInfo = StringUtil.convertBean(obj);
                logMap.putAll(beanInfo);
            }
            UctProtoclClient.getInstance()
                    .doAuditService("auditService", "logOperationSave", logMap);
        } catch (Exception e) {
            log.error(e);
        }
    }

    /**
     * 判断对象数组是否为空
     *
     * @return 如果object为空返回true，不为空返回false
     */
    private boolean isNull(String str) {
        if (str == null) {
            return true;
        }
        str = str.trim();
        if ((str.equalsIgnoreCase("null")) || (str.equals(""))) {
            return true;
        }
        return false;
    }
}
